# 导入flask

from flask import Flask, request

from src.day11.log_util import logger

# 实例化一个app

app = Flask(__name__)


# 定义路由 定义视图函数

@app.route("/")
def hello():
    # 定义返回
    return "Hello Hogwarts"


@app.route("/hogwarts/<name>")
def hogwarts(name):
    return f"欢迎hogwarts的同学：{name}"


@app.route("/user/<int:num>")
def intdemo(num):
    return f"我限定的int类型为{num}"


@app.route("/user/<float:num>")
def floatdemo(num):
    logger.info(f"我限定的float类型为{num}")
    return f"我限定的float类型为{num}"


@app.route("/user1/<num>")
def strdemo(num):
    logger.info(f"我比较宽泛类型为{num}")
    return f"我比较宽泛类型为{num}"


@app.route("/cases", methods=["get", "post"])
def select_case():
    return {"code": 0, "msg": "Get case,success"}


@app.route("/del_cases/<case_id>", methods=["post","get"])
def delete(case_id):
    students = [{"name":"张三","id":1}]
    for s in students:
        if s.get("id") == case_id:
            students.remove(s)
# ssss


if __name__ == '__main__':
    app.run(host="0.0.0.0", port=2388, debug=True)
